<template>
	<div class="article-card">
		<div class="article-card-left">
			<el-image :src="article.imageUrl" alt="Article Image" @click="handleClick" />
		</div>
		<div class="article-card-right">
			<h2 @click="handleClick">{{ article.title }}</h2>
			<p>{{ article.description }}</p>
			<div class="article-card-bottom">
				<span><i class="ri-calendar-schedule-line"></i>&nbsp;{{ props.article.updateDate }}</span>
				<div class="tags">
					<Tag v-for="(tag, index) in props.article.tags.split(',')" :key="index">{{ tag }}</Tag>
				</div>
			</div>
		</div>
	</div>
</template>

<script setup>
import router from '@/router';
import Tag from '../components/Tag.vue';

const props = defineProps({
	article: {
		type: Object,
		required: true
	}
});

function handleClick() {
	router.push({
		name: 'article',
		params: { articleId: props.article.id }
	})
}
</script>

<style scoped>
.article-card {
	display: flex;
	border: 1px solid #ccc;
	border-radius: 8px;
	overflow: hidden;
	margin: 20px 0;
}
.article-card:hover {
	box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
	transform: scale(1.02);
	transition: all 0.3s ease;
}
.article-card:focus {
	outline: none;
	box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
}
.article-card:focus-within {
	box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
}
.article-card:focus-within img {
	transform: scale(1.05);
	transition: all 0.3s ease;
}
.article-card img {
	width: 100%;
	height: auto;
	transition: all 0.3s ease;
}
.article-card img:hover {
	transform: scale(1.05);
	transition: all 0.3s ease;
}
.article-card img:focus {
	outline: none;
	box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
}
.article-card img:focus-within {
	box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
}
.article-card img:focus-within img {
	transform: scale(1.05);
	transition: all 0.3s ease;
}
.article-card img:active {
	transform: scale(0.98);
}
.article-card:active {
	box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
	transform: scale(0.98);
	transition: all 0.3s ease;
}
.article-card:focus-within {
	box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
}
.article-card:focus-within img {
	transform: scale(1.05);
	transition: all 0.3s ease;
}
.article-card img:focus-within {
	box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
}
.article-card img:focus-within img {
	transform: scale(1.05);
	transition: all 0.3s ease;
}
.article-card img:active {
	transform: scale(0.98);
}
.article-card:active {
	transform: scale(0.98);
}
.article-card-left {
	flex: 1;
	max-width: 200px;
	height: 150px;
	overflow: hidden;
	display: flex;
	align-items: center;
	justify-content: center;
}

.article-card-left img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}
.article-card-right {
	flex: 2;
	padding: 20px;
	display: flex;
	flex-direction: column;
	justify-content: space-between;
}
.article-card-right h2 {
	font-size: 1.5em;
	margin-bottom: 10px;
}
.article-card-right h2:hover {
	font-size: 1.5em;
	margin-bottom: 10px;
	cursor: pointer;
	color: #007bff;
}
.article-card-right p {
	font-size: 1em;
	margin-bottom: 20px;
}
.article-card-right button {
	background-color: #007bff;
	color: white;
	border: none;
	padding: 10px 20px;
	border-radius: 5px;
	cursor: pointer;
}
.article-card-right button:hover {
	background-color: #0056b3;
}
.article-card-right button:focus {
	outline: none;
	box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
}
.article-card-right button:active {
	background-color: #004085;
}
.article-card-right button:active {
	transform: scale(0.98);
}
@media (max-width: 768px) {
    .article-card-bottom {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .tags {
        justify-content: flex-start;
        width: 100%;
    }
}
.article-card-bottom {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 20px;
	margin-top: 15px;
}
.article-card-bottom > span {
	color: #444;
	font-size: 14px;
	padding: 5px;
	margin: 5px;
}

.tags {
	display: flex;
	gap: 10px;
	flex-wrap: wrap;
	justify-content: flex-end;
}
.tag {
	color: white;
	padding: 5px 10px;
	border-radius: 5px;
	font-size: 0.9em;
}
</style>
